<template>
  <div class="main-content" style="width: 65%" >
    <p class="front-title">店铺详情</p>
    <div style="padding: 0 50px;">
      <el-row :gutter="20">
        <el-col :span="10" >
          <img :src="merchantData.avatar" class="front-merchant-img">
        </el-col>
        <el-col :span="14">
          <div style="height: 210px;">
            <p class="front-merchant-p">店铺名称：{{merchantData.name}}</p>
            <p class="front-merchant-p">电话：{{merchantData.phone}}</p>
            <p class="front-merchant-p">地址：{{merchantData.address}}</p>
            <p class="front-merchant-p">价格：{{merchantData.price}}/天</p>
          </div>

          <el-button type="warning" style="margin-bottom: 10px;"@click="apply">寄养宠物</el-button>
          <el-button type="primary">服务项目</el-button>
        </el-col>
      </el-row>
    </div>
    <div>评论</div>
    <el-dialog title="请填写信息" :visible.sync="dialogFormVisible" width="40%">
      <el-form :model="form" label-position="right" label-width="100px" style="padding-right: 40px">
        <el-form-item label="宠物">
          <el-select v-model="form.petId" placeholder="请选择" style="width: 100%">

            <el-option
                v-for="item in petData"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="时间">
          <div class="block">
            <el-date-picker
                style="width: 100%"
                value-format="yyyy-MM-dd"
                v-model="selectDate"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
            </el-date-picker>
          </div>

        </el-form-item>
        <el-form-item label="备注">
          <el-input  type="textarea" :rows="2" v-model="form.remark" autocomplete="off"></el-input>
        </el-form-item>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button  @click="dialogFormVisible = false">取 消</el-button>
        <el-button  type="primary" @click="save">保 存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import request from "@/utils/request";


export default {
  data() {

    return {
      selectDate:'',
      user: JSON.parse(localStorage.getItem('userInfo') || '{}'),
      form:{},
      dialogFormVisible:false,
      merchantData:{},
      merchantId:this.$route.query.id,
      petData:{},
    }
  },
  created () {
    this.loadData()
    console.log(this.merchantId)
  },
  mounted() {

  },
  // methods：本页面所有的点击事件或者其他函数定义区
  methods: {
    loadData(){
      request.get("/merchant/selectById/"+this.merchantId).then(res=>{
        if (res.code=='0'){
          this.merchantData=res.data
          console.log(res.data)
        }
        else {
          this.$message.error(res.msg)
        }
      })
    },
    loadPetData(){

      request.get("/pet/selectAll/").then(res=>{
        if (res.code=='0'){
          this.petData=res.data
          console.log(res.data)
        }
        else {
          this.$message.error(res.msg)
        }
      })
    },
    apply(){
      this.form={}
      this.loadPetData()
      this.dialogFormVisible=true
    },
    save(){
      this.form.merchantId=this.merchantId
      this.form.startDate=this.selectDate[0]
      this.form.endDate=this.selectDate[1]
      request.post("fosterOrder/save", this.form).then(res => {
        if (res.code === '0') {
          this.$message.success('寄养预约成功');
          this.dialogFormVisible = false
        }
        else{
          this.$message.error(res.msg)
        }
      })
    }


  }
}
</script>
<style>

</style>